package com.example.consummer.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queuesToDeclare = @Queue("work.queue"))
public class WorkCosumer1 {
    @RabbitHandler
    public void process(String val, Channel channel, Message message) {
        System.out.println("1111111111 rev : " + val);
        try {
            //需要手动进行确认消息
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
            //手动返回未确认消息,requeue 为true时,重新入队
//            channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
            Thread.sleep(10);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
